package d.k;

import d.c;
import d.h.b.d;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

class n extends m {

    static final class a extends d implements d.h.a.b<CharSequence, Integer, c<? extends Integer, ? extends Integer>> {

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ List f2718b;

        /* renamed from: c  reason: collision with root package name */
        final /* synthetic */ boolean f2719c;

        /* JADX INFO: super call moved to the top of the method (can break code semantics) */
        a(List list, boolean z) {
            super(2);
            this.f2718b = list;
            this.f2719c = z;
        }

        public /* bridge */ /* synthetic */ Object a(Object obj, Object obj2) {
            return c((CharSequence) obj, ((Number) obj2).intValue());
        }

        public final c<Integer, Integer> c(CharSequence charSequence, int i) {
            d.h.b.c.c(charSequence, "$receiver");
            c e = n.f(charSequence, this.f2718b, i, this.f2719c, false);
            if (e != null) {
                return d.d.a(e.c(), Integer.valueOf(((String) e.d()).length()));
            }
            return null;
        }
    }

    static final class b extends d implements d.h.a.a<d.i.c, String> {

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ CharSequence f2720b;

        /* JADX INFO: super call moved to the top of the method (can break code semantics) */
        b(CharSequence charSequence) {
            super(1);
            this.f2720b = charSequence;
        }

        /* renamed from: c */
        public final String b(d.i.c cVar) {
            d.h.b.c.c(cVar, "it");
            return n.s(this.f2720b, cVar);
        }
    }

    /* access modifiers changed from: private */
    public static final c<Integer, String> f(CharSequence charSequence, Collection<String> collection, int i, boolean z, boolean z2) {
        int i2;
        T t;
        String str;
        T t2;
        if (z || collection.size() != 1) {
            d.i.a cVar = !z2 ? new d.i.c(f.a(i, 0), charSequence.length()) : f.d(f.b(i, g(charSequence)), 0);
            if (charSequence instanceof String) {
                i2 = cVar.a();
                int b2 = cVar.b();
                int c2 = cVar.c();
                if (c2 < 0 ? i2 >= b2 : i2 <= b2) {
                    while (true) {
                        Iterator<T> it = collection.iterator();
                        while (true) {
                            if (!it.hasNext()) {
                                t2 = null;
                                break;
                            }
                            t2 = it.next();
                            String str2 = (String) t2;
                            if (m.b(str2, 0, (String) charSequence, i2, str2.length(), z)) {
                                break;
                            }
                        }
                        str = (String) t2;
                        if (str == null) {
                            if (i2 == b2) {
                                break;
                            }
                            i2 += c2;
                        } else {
                            break;
                        }
                    }
                }
                return null;
            }
            int a2 = cVar.a();
            int b3 = cVar.b();
            int c3 = cVar.c();
            if (c3 < 0 ? a2 >= b3 : a2 <= b3) {
                while (true) {
                    Iterator<T> it2 = collection.iterator();
                    while (true) {
                        if (!it2.hasNext()) {
                            t = null;
                            break;
                        }
                        t = it2.next();
                        String str3 = (String) t;
                        if (p(str3, 0, charSequence, i2, str3.length(), z)) {
                            break;
                        }
                    }
                    str = (String) t;
                    if (str == null) {
                        if (i2 == b3) {
                            break;
                        }
                        a2 = i2 + c3;
                    } else {
                        break;
                    }
                }
            }
            return null;
            return d.d.a(Integer.valueOf(i2), str);
        }
        String str4 = (String) q.a(collection);
        CharSequence charSequence2 = charSequence;
        String str5 = str4;
        int i3 = i;
        int k = !z2 ? k(charSequence2, str5, i3, false, 4, (Object) null) : m(charSequence2, str5, i3, false, 4, (Object) null);
        if (k < 0) {
            return null;
        }
        return d.d.a(Integer.valueOf(k), str4);
    }

    public static final int g(CharSequence charSequence) {
        d.h.b.c.c(charSequence, "$this$lastIndex");
        return charSequence.length() - 1;
    }

    public static final int h(CharSequence charSequence, String str, int i, boolean z) {
        d.h.b.c.c(charSequence, "$this$indexOf");
        d.h.b.c.c(str, "string");
        if (!z && (charSequence instanceof String)) {
            return ((String) charSequence).indexOf(str, i);
        }
        return j(charSequence, str, i, charSequence.length(), z, false, 16, (Object) null);
    }

    private static final int i(CharSequence charSequence, CharSequence charSequence2, int i, int i2, boolean z, boolean z2) {
        d.i.a cVar = !z2 ? new d.i.c(f.a(i, 0), f.b(i2, charSequence.length())) : f.d(f.b(i, g(charSequence)), f.a(i2, 0));
        if (!(charSequence instanceof String) || !(charSequence2 instanceof String)) {
            int a2 = cVar.a();
            int b2 = cVar.b();
            int c2 = cVar.c();
            if (c2 >= 0) {
                if (a2 > b2) {
                    return -1;
                }
            } else if (a2 < b2) {
                return -1;
            }
            while (true) {
                if (p(charSequence2, 0, charSequence, a2, charSequence2.length(), z)) {
                    return a2;
                }
                if (a2 == b2) {
                    return -1;
                }
                a2 += c2;
            }
        } else {
            int a3 = cVar.a();
            int b3 = cVar.b();
            int c3 = cVar.c();
            if (c3 >= 0) {
                if (a3 > b3) {
                    return -1;
                }
            } else if (a3 < b3) {
                return -1;
            }
            while (true) {
                if (m.b((String) charSequence2, 0, (String) charSequence, a3, charSequence2.length(), z)) {
                    return a3;
                }
                if (a3 == b3) {
                    return -1;
                }
                a3 += c3;
            }
        }
    }

    static /* synthetic */ int j(CharSequence charSequence, CharSequence charSequence2, int i, int i2, boolean z, boolean z2, int i3, Object obj) {
        return i(charSequence, charSequence2, i, i2, z, (i3 & 16) != 0 ? false : z2);
    }

    public static /* synthetic */ int k(CharSequence charSequence, String str, int i, boolean z, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            i = 0;
        }
        if ((i2 & 4) != 0) {
            z = false;
        }
        return h(charSequence, str, i, z);
    }

    public static final int l(CharSequence charSequence, String str, int i, boolean z) {
        d.h.b.c.c(charSequence, "$this$lastIndexOf");
        d.h.b.c.c(str, "string");
        return (z || !(charSequence instanceof String)) ? i(charSequence, str, i, 0, z, true) : ((String) charSequence).lastIndexOf(str, i);
    }

    public static /* synthetic */ int m(CharSequence charSequence, String str, int i, boolean z, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            i = g(charSequence);
        }
        if ((i2 & 4) != 0) {
            z = false;
        }
        return l(charSequence, str, i, z);
    }

    private static final d.j.a<d.i.c> n(CharSequence charSequence, String[] strArr, int i, boolean z, int i2) {
        if (i2 >= 0) {
            return new c(charSequence, i, i2, new a(d.a(strArr), z));
        }
        throw new IllegalArgumentException(("Limit must be non-negative, but was " + i2 + '.').toString());
    }

    static /* synthetic */ d.j.a o(CharSequence charSequence, String[] strArr, int i, boolean z, int i2, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            i = 0;
        }
        if ((i3 & 4) != 0) {
            z = false;
        }
        if ((i3 & 8) != 0) {
            i2 = 0;
        }
        return n(charSequence, strArr, i, z, i2);
    }

    public static final boolean p(CharSequence charSequence, int i, CharSequence charSequence2, int i2, int i3, boolean z) {
        d.h.b.c.c(charSequence, "$this$regionMatchesImpl");
        d.h.b.c.c(charSequence2, "other");
        if (i2 < 0 || i < 0 || i > charSequence.length() - i3 || i2 > charSequence2.length() - i3) {
            return false;
        }
        for (int i4 = 0; i4 < i3; i4++) {
            if (!b.a(charSequence.charAt(i + i4), charSequence2.charAt(i2 + i4), z)) {
                return false;
            }
        }
        return true;
    }

    public static final d.j.a<String> q(CharSequence charSequence, String[] strArr, boolean z, int i) {
        d.h.b.c.c(charSequence, "$this$splitToSequence");
        d.h.b.c.c(strArr, "delimiters");
        return g.d(o(charSequence, strArr, 0, z, i, 2, (Object) null), new b(charSequence));
    }

    public static /* synthetic */ d.j.a r(CharSequence charSequence, String[] strArr, boolean z, int i, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            z = false;
        }
        if ((i2 & 4) != 0) {
            i = 0;
        }
        return q(charSequence, strArr, z, i);
    }

    public static final String s(CharSequence charSequence, d.i.c cVar) {
        d.h.b.c.c(charSequence, "$this$substring");
        d.h.b.c.c(cVar, "range");
        return charSequence.subSequence(cVar.g().intValue(), cVar.f().intValue() + 1).toString();
    }
}
